const express = require('express');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const login = require('./route/auth');
const db = require('./db/mongo')

var app = express();
db.conn.on('error', console.error.bind(console, "DB has an error: "));
db.conn.once('open', () => {
    console.log('hello mongoDB!')
});
app.use(cookieParser())
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())


app.use(session({
    secret:"Documents@Sccba.123",
    cookie: {
        path: "/",
        httpOnly: true,
        maxAge: 24 * 60 * 60 * 1000,
    }
}))
app.use('/api/login',login)
app.get('/', (req, res, next) => {
    res.send('good job, first web')
})


module.exports = app